package org.example.hw;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author: lynn
 * @Descript: 流写法
 * @date: 2021/2/27 20:05
 * @version: 1.0
 */
public class test22 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
         List<Fruit> fruitList = new ArrayList<>();
        Boolean flag = true;
        int size = 0;
        while (scanner.hasNext()) {
            if (flag) {
                size = scanner.nextInt();
                flag = false;
                continue;
            }

            String s=scanner.nextLine();
            if (s.equals("-1")){
                break;
            }
            if (s!=null && !s.equals("")){
                String[] fruit = s.split(" ");
                Fruit fruit1=new Fruit();
                fruit1.setFruitName(fruit[0]);
                fruit1.setWorkNo(fruit[1]);
                fruit1.setFruitWeight(fruit[2]);
                fruitList.add(fruit1);
            }
        }

        Optional.of(fruitList.stream()
                .sorted(Comparator.comparing(Fruit::getWorkNo))
                .sorted(Comparator.comparing(Fruit::getFruitWeight))
                .sorted(Comparator.comparing(Fruit::getFruitName))
                .collect(Collectors.toList()))
                .ifPresent(v -> {
                    for (int i = 0; i <v.size() ; i++) {
                        System.out.println(v.get(i).getFruitName()+" "
                                +v.get(i).getWorkNo()+" "+v.get(i).getFruitWeight());
                    };
        });
    }


    static  class  Fruit {
        public String fruitName;
        public String workNo;
        public String fruitWeight;


        public void setFruitName(String fruitName) {
            this.fruitName = fruitName;
        }

        public void setWorkNo(String workNo) {
            this.workNo = workNo;
        }

        public void setFruitWeight(String fruitWeight) {
            this.fruitWeight = fruitWeight;
        }

        public String getFruitName() {
            return fruitName;
        }

        public String getWorkNo() {
            return workNo;
        }

        public String getFruitWeight() {
            return fruitWeight;
        }
    }
}